<template>
	<div class="app-container">
		<!-- 搜索 -->
		<div class="filter-container tw-filter">
			<el-button class="filter-item tw-filter-button" size="medium" icon="el-icon-edit"
				v-has="$store.state.user.btn_common+'add'" @click="handleAdd()">添加</el-button>
			<el-button class="filter-item tw-filter-button" size="medium" icon="el-icon-delete"
				v-has="$store.state.user.btn_common+'del'" @click="handleDelete()">批量删除</el-button>

			<el-input v-model="queryList.title" placeholder="请输入标题" class="filter-item tw-filter-input" clearable />
			<el-select v-model="queryList.grade_id" class="filter-item tw-filter-input" placeholder="请选择级别" clearable>
				<el-option v-for="item in articleGradeListAll" :key="item.key" filter="false" :label="item.value"
					:value="item.key"></el-option>
			</el-select>
			<el-cascader @change="getIndustryList2(queryList.c_id, 1)" placeholder="请选择分类"
				class="filter-item tw-filter-input" style="width: 240px; margin-right:10px" v-model="queryList.c_id"
				clearable filterable :options="classListAll"
				:props="{ checkStrictly: true, expandTrigger: 'hover', value:'id', label:'name', emitPath: false}"
				separator=" > ">
			</el-cascader>
			<el-select v-model="queryList.industry_id" class="filter-item tw-filter-input" placeholder="请选择行业" clearable
				filterable>
				<el-option v-for="item in industryListAll" :key="item.id" filter="false" :label="item.name"
					:value="item.id"></el-option>
			</el-select>
			<el-select v-model="queryList.unit_id" class="filter-item tw-filter-input" placeholder="请选择发布单位" clearable
				filterable v-if="$store.state.user.adminInfo.unit_id == 0">
				<el-option v-for="item in unitListAll" :key="item.id" filter="false" :label="item.name"
					:value="item.id"></el-option>
			</el-select>
			<el-select v-model="queryList.tag" class="filter-item tw-filter-input" placeholder="请选择标签" clearable
				filterable>
				<el-option v-for="item in tagListAll" :key="item.id" filter="false" :label="item.name"
					:value="item.id"></el-option>
			</el-select>
			<el-select v-model="queryList.is_grade" class="filter-item tw-filter-input" placeholder="政策类型" clearable>
				<el-option key="" label="全部类型" value="" />
				<el-option key="0" label="惠企政策" value="0" />
				<el-option key="1" label="申报指南" value="1" />
			</el-select>
			<el-select v-model="queryList.state" class="filter-item tw-filter-input" placeholder="请选择状态" clearable>
				<el-option key="" label="全部状态" value="" />
				<el-option key="1" label="启用" value="1" />
				<el-option key="0" label="禁用" value="0" />
			</el-select>

			<el-button v-waves class="filter-item tw-filter-button" size="medium" icon="el-icon-search"
				@click="handleFilter">搜索</el-button>
		</div>

		<!-- 表格内容 -->
		<el-table v-loading="listLoading" :data="tableList" @selection-change="handleSelectionChange" border fit
			highlight-current-row style="width: 100%;">
			<el-table-column type="selection" width="50" />
			<!-- <el-table-column label="排序" prop="sort_id" align="center" width="80" v-has="$store.state.user.btn_common+'edit'">
				<template slot-scope="{row}">
					<el-input v-model="row.sort_id" class="edit-input" size="small" @change="updateSort(row.id,row.sort_id)" />
				</template>
			</el-table-column> -->
			<el-table-column label="ID" prop="id" align="center" width="80" />
			<el-table-column label="标题" prop="title" align="left" />
			<el-table-column label="级别" prop="grade_name" align="left" />
			<el-table-column label="发布单位" prop="unit_name" align="left" />
			<el-table-column label="分类" prop="c_name" align="left" />
			<el-table-column label="行业" prop="industry_name" align="left" />
			<el-table-column label="标签" prop="tag_name" align="left" />
			<!-- <el-table-column label="第三方URL" prop="third_url" align="left" width="200px" /> -->
			<!-- <el-table-column label="简介" prop="desc" align="left" />
			<el-table-column label="封面图" prop="image_src" align="center">
				<template slot-scope="{row}">
					<el-image style="width: 100px; height: 100px" fit="cover" v-if="row.image_src" :src="row.image_src_str" :preview-src-list="[row.image_src_str]"></el-image>
				</template>
			</el-table-column> -->
			<el-table-column label="政策类型" align="center">
				<template slot-scope="{row}">
					<span v-if="row.is_grade == 1">申报指南</span>
					<span v-else>惠企政策</span>
				</template>
			</el-table-column>
			<el-table-column label="添加时间" align="center">
				<template slot-scope="{row}">
					<span>{{ row.add_time | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="编辑时间" align="center">
				<template slot-scope="{row}">
					<span>{{ row.edit_time | parseTime('{y}-{m}-{d} {h}:{i}:{s}') }}</span>
				</template>
			</el-table-column>
			<el-table-column label="发布人" align="center">
				<template slot-scope="{row}">
					<span v-if="row.admin_real_name">{{row.admin_real_name}}</span>
				</template>
			</el-table-column>
			<el-table-column label="点击数" prop="click_num" align="center" />
			<el-table-column label="状态" align="center">
				<template slot-scope="{row}">
					<span v-if="row.state == 1">启用</span>
					<span v-else>禁用</span>
				</template>
			</el-table-column>
			<el-table-column label="是否包含敏感词" align="center">
				<template slot-scope="{row}">
					<span v-if="row.verify_state == 3" style="color:#f44;">是</span>
					<span v-else></span>
				</template>
			</el-table-column>
			<el-table-column label="包含敏感词" align="left">
				<template slot-scope="{row}">
					<span v-if="row.verify_remarks" style="color:#f44;">{{row.verify_remarks}}</span>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="220" align="center" class-name="small-padding fixed-width">
				<template slot-scope="{row}">
					<el-button size="mini" v-has="$store.state.user.btn_common+'edit'"
						@click="handleEdit(row.id)">编辑</el-button>
					<el-button size="mini" v-has="$store.state.user.btn_common+'upshow'" v-if="row.state"
						@click="handleUpshow(row.id)">禁用</el-button>
					<el-button size="mini" v-has="$store.state.user.btn_common+'show'" v-else
						@click="handleShow(row.id)">启用</el-button>
					<el-button size="mini" v-has="$store.state.user.btn_common+'del'"
						@click="handleDelete(row.id)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>
		<pagination v-show="isPage && listTotal > 0" :total="listTotal" :page.sync="queryList.curpage"
			:limit.sync="queryList.page" @pagination="getList" />

		<!-- 添加/编辑 -->
		<el-dialog width="60%" @close="resetForm('dataForm')" :title="textMap[dialogStatus]"
			:visible.sync="dialogFormVisible">
			<el-form label-position="right" label-width="120px" ref="dataForm" :rules="rules" :model="form">
				<el-form-item label="标题" prop="title">
					<el-input v-model="form.title" placeholder="请输入标题" />
				</el-form-item>
				<!-- <el-form-item label="二级标题" prop="two_title">
        	<el-input v-model="form.two_title" placeholder="请输入二级标题"/>
        </el-form-item> -->
				<el-form-item label="级别" prop="grade_id">
					<el-select v-model="form.grade_id" class="filter-item" placeholder="请选择类型" style="display:block;">
						<el-option v-for="item in articleGradeList" :key="item.key" filter="false" :label="item.value"
							:value="item.key"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="发布单位" prop="unit_id" v-if="$store.state.user.adminInfo.unit_id == 0">
					<el-select v-model="form.unit_id" placeholder="请选择发布单位" style="width: 100%" filterable>
						<el-option v-for="item in unitList" :key="item.id" :label="item.name"
							:value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="所属分类" prop="c_id">
					<el-cascader @change="getIndustryList(queryList.c_id, 1)" placeholder="请选择所属分类" v-model="form.c_id"
						:options="classList"
						:props="{ checkStrictly: false, expandTrigger: 'hover', value: 'id', label: 'name', emitPath:false}"
						separator="> " style="width: 100%" filterable></el-cascader>
				</el-form-item>
				<el-form-item label="行业" prop="industry_id">
					<el-select v-model="form.industry_id" placeholder="请选择行业" style="width: 100%" filterable>
						<el-option v-for="item in industryList" :key="item.id" :label="item.name"
							:value="item.id"></el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="标签" prop="tag_arr">
					<el-select v-model="form.tag_arr" multiple class="filter-item" placeholder="请选择标签"
						style="display:block;" filterable>
						<el-option v-for="item in tagList" :key="item.id" filter="false" :label="item.name"
							:value="item.id"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="政策开始时间" prop="start_time_str">
					<el-date-picker v-model="form.start_time_str" type="date" placeholder="请选择开始日期(不选择则长期有效)"
						value-format="yyyy-MM-dd" style="width:100%" clearable />
				</el-form-item>
				<el-form-item label="政策结束时间" prop="end_time_str">
					<el-date-picker v-model="form.end_time_str" type="date" placeholder="请选择结束日期(不选择则长期有效)"
						value-format="yyyy-MM-dd" style="width:100%" clearable />
				</el-form-item>
				<el-form-item label="时间备注内容" prop="time_remarks">
					<el-input v-model="form.time_remarks" placeholder="请输入时间备注内容" />
				</el-form-item>
				<!-- <el-form-item label="封面图片">
          <UploadOne v-on:uploadCallBack="uploadCallBack($event, 'image_src')" :showUrl="form.image_src_str" :formData="{dir_type: apiPath}" tip="支持格式gif,jpg,png"></UploadOne>
        </el-form-item>
				<el-form-item label="简介" prop="desc">
				  <el-input v-model="form.desc" type="textarea" :rows="3" maxlength="250" show-word-limit placeholder="请输入简介" />
				</el-form-item> -->
				<el-form-item label="政策类型" prop="is_grade">
					<el-radio-group v-model="form.is_grade">
						<el-radio :label="0">惠企政策</el-radio>
						<el-radio :label="1">申报指南</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="第一次导入" prop="details" style="margin-bottom: 30px;" v-show="!form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv15" ref="content15" v-model="form.details"
						:height="200" />
				</el-form-item>
				<el-form-item label="核心条款" prop="details1" style="margin-bottom: 30px;" v-show="!form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv10" ref="content10" v-model="form.details1"
						:height="200" />
				</el-form-item>
				<el-form-item label="享受主体" prop="details2" style="margin-bottom: 30px;" v-show="!form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv11" ref="content11" v-model="form.details2"
						:height="100" />
				</el-form-item>
				<el-form-item label="政策依据" prop="details3" style="margin-bottom: 30px;" v-show="!form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv12" ref="content12" v-model="form.details3"
						:height="100" />
				</el-form-item>
				<el-form-item label="政策时限" prop="details4" style="margin-bottom: 30px;" v-show="!form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv13" ref="content13" v-model="form.details4"
						:height="100" />
				</el-form-item>
				<el-form-item label="主管单位及咨询电话" prop="details5" style="margin-bottom: 30px;" v-show="!form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv14" ref="content14" v-model="form.details5"
						:height="200" />
				</el-form-item>

				<el-form-item label="原文内容" prop="details1" style="margin-bottom: 30px;" v-show="form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv20" ref="content20" v-model="form.details1"
						:height="200" />
				</el-form-item>
				<el-form-item label="办事链接" prop="third_url" v-if="form.is_grade">
					<el-input v-model="form.third_url" placeholder="请输入办事链接" />
				</el-form-item>
				<el-form-item label="适用区域" prop="applicable_area" v-if="form.is_grade">
					<el-input v-model="form.applicable_area" placeholder="请输入适用区域" />
				</el-form-item>
				<el-form-item label="办理地址" prop="processing_address" v-if="form.is_grade">
					<el-input v-model="form.processing_address" placeholder="请输入办理地址" />
				</el-form-item>
				<el-form-item label="办公时间" prop="office_hours" v-if="form.is_grade">
					<el-input v-model="form.office_hours" placeholder="请输入办公时间" />
				</el-form-item>
				<el-form-item label="注意事项" prop="matters_needing_attention" v-if="form.is_grade">
					<el-input v-model="form.matters_needing_attention" type="textarea" :rows="3" maxlength="250"
						show-word-limit placeholder="请输入注意事项" />
				</el-form-item>

				<!-- 办理条件 -->
				<el-form-item label="办理条件" filter="false" v-if="form.is_grade">
					<i class="el-icon-circle-plus" @click="addRowHeader()" style="font-size: 25px;color: #409EFF;"></i>
				</el-form-item>
				<div style="padding-left: 120px;margin-bottom: 10px;" v-if="form.is_grade">
					<el-table ref="multipleTable" key="10" :data="form.details3_array" border style="width: 100%;">
						<el-table-column label="名称" prop="name" align="center" width="280">
							<template slot-scope="scope">
								<el-input v-model="scope.row.name" type="textarea" :rows="3" class="edit-input"
									size="small" />
							</template>
						</el-table-column>
						<el-table-column label="说明" prop="remarks" align="center" width="270">
							<template slot-scope="scope">
								<el-input v-model="scope.row.remarks" type="textarea" :rows="3" class="edit-input"
									size="small" />
							</template>
						</el-table-column>
						<el-table-column label="操作" align="center" width="90">
							<template slot-scope="scope">
								<i class="el-icon-circle-plus" @click="addRowHeader(scope.$index+1)"
									style="font-size: 25px;color: #409EFF;"></i>
								<i class="el-icon-remove-outline" @click="delRowHeader(scope.$index)"
									style="font-size: 25px;margin-left: 5px;"></i>
							</template>
						</el-table-column>
					</el-table>
				</div>
				<!-- <el-form-item label="办理条件" prop="details3" style="margin-bottom: 30px;" v-show="form.is_grade">
           <Tinymce v-if="dialogFormVisible" id="someDiv3" ref="content3" v-model="form.details3" :height="200" />
         </el-form-item> -->

				<!-- 办理材料 -->
				<el-form-item label="办理材料" filter="false" v-if="form.is_grade">
					<i class="el-icon-circle-plus" @click="addRowParam()" style="font-size: 25px;color: #409EFF;"></i>
				</el-form-item>
				<div style="padding-left: 120px;margin-bottom: 10px;" v-if="form.is_grade">
					<el-table ref="multipleTable" key="11" :data="form.details4_array" border style="width: 100%;">
						<el-table-column label="名称" prop="name" align="center" width="220">
							<template slot-scope="scope">
								<el-input v-model="scope.row.name" type="textarea" :rows="3" class="edit-input"
									size="small" />
							</template>
						</el-table-column>
						<el-table-column label="选项1" prop="option1" align="center" width="90">
							<template slot-scope="scope">
								<el-checkbox v-model="scope.row.is_option1">选择</el-checkbox>
								<el-input v-model="scope.row.option1" class="edit-input" size="small" />
							</template>
						</el-table-column>
						<el-table-column label="选项2" prop="option2" align="center" width="90">
							<template slot-scope="scope">
								<el-checkbox v-model="scope.row.is_option2">选择</el-checkbox>
								<el-input v-model="scope.row.option2" class="edit-input" size="small" />
							</template>
						</el-table-column>
						<el-table-column label="选项3" prop="option3" align="center" width="90">
							<template slot-scope="scope">
								<el-checkbox v-model="scope.row.is_option3">选择</el-checkbox>
								<el-input v-model="scope.row.option3" class="edit-input" size="small" />
							</template>
						</el-table-column>
						<el-table-column label="是否标题" prop="is_title" align="center" width="90">
							<template slot-scope="scope">
								<el-checkbox v-model="scope.row.is_title"></el-checkbox>
							</template>
						</el-table-column>
						<el-table-column label="操作" align="center" width="90">
							<template slot-scope="scope">
								<i class="el-icon-circle-plus" @click="addRowParam(scope.$index+1)"
									style="font-size: 25px;color: #409EFF;"></i>
								<i class="el-icon-remove-outline" @click="delRowParam(scope.$index)"
									style="font-size: 25px;margin-left: 5px;"></i>
							</template>
						</el-table-column>
					</el-table>
				</div>
				<!-- <el-form-item label="办理材料" prop="details4" style="margin-bottom: 30px;" v-show="form.is_grade">
          <Tinymce v-if="dialogFormVisible" id="someDiv4" ref="content4" v-model="form.details4" :height="200" />
        </el-form-item> -->


				<el-form-item label="办理流程" prop="details5" style="margin-bottom: 30px;" v-show="form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv5" ref="content5" v-model="form.details5"
						:height="200" />
				</el-form-item>
				<el-form-item label="奖补标准" prop="details6" style="margin-bottom: 30px;" v-show="form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv6" ref="content6" v-model="form.details6"
						:height="200" />
				</el-form-item>
				<el-form-item label="收费情况" prop="details7" style="margin-bottom: 30px;" v-show="form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv7" ref="content7" v-model="form.details7"
						:height="200" />
				</el-form-item>
				<el-form-item label="其他相关政策" prop="details8" style="margin-bottom: 30px;" v-show="form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv8" ref="content8" v-model="form.details8"
						:height="200" />
				</el-form-item>
				<el-form-item label="常见问题" prop="details9" style="margin-bottom: 30px;" v-show="form.is_grade">
					<Tinymce v-if="dialogFormVisible" id="someDiv9" ref="content9" v-model="form.details9"
						:height="200" />
				</el-form-item>
				<el-form-item label="上传附件">
					<UploadOssOne v-if="uploadShow" v-on:uploadCallBack="uploadCallBack2($event,'wj_url')">点击上传
					</UploadOssOne>
				</el-form-item>
				<el-form-item label="附件URL" prop="wj_url">
					<el-input v-model="form.wj_url" placeholder="上传附件" />
				</el-form-item>


				<el-form-item label="状态" prop="state">
					<el-radio-group v-model="form.state">
						<el-radio :label="1">启用</el-radio>
						<el-radio :label="0">禁用</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item label="排序" prop="sort_id">
					<el-input v-model="form.sort_id" class="tw-w-200" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="dialogStatus==='create'?createData():updateData()">保存</el-button>
				<el-button @click="dialogFormVisible = false">取消</el-button>
			</div>
		</el-dialog>
	</div>
</template>

<script>
	import Pagination from '@/components/Pagination' // 基于el分页的二次封装
	import waves from '@/directive/waves' // waves directive
	import Tinymce from '@/components/Tinymce' // 富文本编辑器
	import UploadOne from '@/components/Upload/UploadOne'
	import UploadOssOne from '@/components/Upload/UploadOssOne'

	export default {
		components: {
			Pagination,
			Tinymce,
			UploadOne,
			UploadOssOne
		},
		directives: {
			waves
		},
		data() {
			return {
				//上传附件置
				uploadShow: false,
				// 数据列表
				listLoading: true,
				listTotal: 0,
				isPage: false,
				tableList: [],
				multipleSelection: [], //多选数据
				// 添加/编辑弹窗
				dialogFormVisible: false,
				dialogStatus: '',
				textMap: {
					update: '编辑',
					create: '添加'
				},
				//键字段
				keyName: 'id',
				apiPath: 'cms.article',
				apiPath1: 'cms.articleclass',
				apiPath2: 'cms.industry',
				apiPath3: 'cms.unit',
				apiPath4: 'cms.tag',

				// 搜索数据
				queryList: {
					page: this.$store.state.settings.page, // 每页显示数量
					curpage: 1, // 当前页码
					title: '', //  标题
					c_id: null, //分类ID
					industry_id: null,
					unit_id: null,
					grade_id: null,
					tag: null,
					is_grade: null,
					state: null
				},

				// 表单数据
				form: {
					id: '',
					title: '', //标题
					two_title: '',
					grade_id: '',
					c_id: '', //分类ID
					industry_id: '',
					unit_id: '',
					tag: '',
					tag_arr: [],
					time_remarks: '',
					third_url: '',
					desc: '', //简介
					image_src: '', //封面图片url
					image_src_str: '',
					details: '', //内容（富文本）
					is_grade: 0,
					details1: '',
					details2: '',
					details3: '',
					details4: '',
					details5: '',
					details6: '',
					details7: '',
					details8: '',
					details9: '',
					details3_array: [],
					details4_array: [],

					applicable_area: '',
					processing_address: '',
					office_hours: '',
					matters_needing_attention: '',

					wj_url: '',
					state: 1, //状态，0禁用，1启用
					sort_id: 255, //排序
					start_time_str: '', //开始时间
					end_time_str: '', //结束时间
				},
				// 重置数据
				formReset: {
					id: '',
					title: '', //标题
					two_title: '',
					grade_id: '',
					c_id: '', //分类ID
					industry_id: '',
					unit_id: '',
					tag: '',
					tag_arr: [],
					time_remarks: '',
					third_url: '',
					desc: '', //简介
					image_src: '', //封面图片url
					image_src_str: '',
					details: '', //内容（富文本）
					is_grade: 0,
					details1: '',
					details2: '',
					details3: '',
					details4: '',
					details5: '',
					details6: '',
					details7: '',
					details8: '',
					details9: '',
					details3_array: [],
					details4_array: [],

					applicable_area: '',
					processing_address: '',
					office_hours: '',
					matters_needing_attention: '',

					wj_url: '',
					state: 1, //状态，0禁用，1启用
					sort_id: 255, //排序
					start_time_str: '', //开始时间
					end_time_str: '', //结束时间
				},
				// 验证
				rules: {
					title: [{
						required: true,
						message: '请输入标题！',
						trigger: 'change'
					}],
					grade_id: [{
						required: true,
						message: '请选择级别！',
						trigger: 'blur'
					}],
					c_id: [{
						required: true,
						message: '请选择所属分类！',
						trigger: 'blur'
					}],
					//industry_id: [{ required: true, message: '请选择行业分类！', trigger: 'blur' }],
					unit_id: [{
						required: true,
						message: '请选择单位！',
						trigger: 'blur'
					}],
				},


				//级别列表
				articleGradeListAll: [],
				articleGradeList: [],
				// 文章分类列表
				classListAll: [],
				classList: [],
				//行业分类列表
				industryListAll: [],
				industryList: [],
				//单位列表
				unitListAll: [],
				unitList: [],
				//标签列表
				tagListAll: [],
				tagList: [],
			}
		},
		created() {
			//获取数据列表
			this.getList()
			//获取分类列表
			this.getClassList()
			//获取行业分类列表
			this.getIndustryList()
			//获取单位列表
			this.getUnitList()
			//获取标签列表
			this.getUnitListList()
			//获取级别列表
			this.getGradeList()
		},
		methods: {
			//获取级别列表
			getGradeList() {
				this.$api.fetchListDictionary({
					ident: 'article_grade'
				}).then(response => {
					this.articleGradeList = JSON.parse(JSON.stringify(response.list));
					// 数据处理
					response.list.unshift({
						key: '0',
						value: '全部级别'
					})
					this.articleGradeListAll = response.list
				})
			},
			//获取分类列表
			getClassList() {
				this.$api.fetchList({}, this.apiPath1).then((response) => {
					this.classList = JSON.parse(JSON.stringify(response.list))
					response.list.unshift({
						id: '0',
						name: '全部文章分类'
					})
					this.classListAll = response.list
				})
			},

			// 获取行业分类列表
			getIndustryList(c_id = 0, is_linkage = 0) {
				c_id = 0
				if (is_linkage) {
					this.form.industry_id = ''
				}
				this.$api.fetchList({
					c_id: c_id
				}, this.apiPath2).then(response => {
					this.industryList = JSON.parse(JSON.stringify(response.list))
					response.list.unshift({
						id: '',
						name: '全部行业分类',
					})
					this.industryListAll = response.list
				})
			},
			//获取行业分类列表2
			getIndustryList2(c_id = 0, is_linkage = 0) {
				/*if(is_linkage){
				  this.queryList.industry_id = ''
				  this.industryListAll = []
				}
				if(c_id){
				  this.$api.fetchList({c_id: c_id}, this.apiPath2).then(response => {
				  	response.list.unshift({
				  		id: '',
				  		name: '全部行业分类',
				  	})
				  	this.industryListAll = response.list
				  })
				}*/
			},
			//获取单位列表
			getUnitList() {
				this.$api.fetchList({}, this.apiPath3).then((response) => {
					this.unitList = JSON.parse(JSON.stringify(response.list))
					response.list.unshift({
						id: '0',
						name: '全部单位'
					})
					this.unitListAll = response.list
				})
			},
			//获取标签列表
			getUnitListList() {
				this.$api.fetchList({}, this.apiPath4).then((response) => {
					this.tagList = JSON.parse(JSON.stringify(response.list))
					response.list.unshift({
						id: '0',
						name: '全部分类'
					})
					this.tagListAll = response.list
				})
			},
			//文件上传回调
			uploadCallBack(res, fieldName = '') {
				if (fieldName) {
					this.form[fieldName] = res.fileName;
					this.form[fieldName + '_str'] = res.showUrl;
				} else {
					this.$message('图片字段错误！');
				}
			},
			//附件上传回调
			uploadCallBack2(res, fieldName = '') {
				this.form.size = res.size;
				if (fieldName) {
					this.form[fieldName] = res.fileName;
				} else {
					this.$message('附件字段错误！');
				}
			},

			/*******************************公共方法******************************/
			// 搜索
			handleFilter() {
				this.queryList.curpage = 1
				this.tableList = []
				this.listTotal = 0
				this.getList()
			},
			// 列表选择
			handleSelectionChange(val) {
				this.multipleSelection = val
			},
			// 重置form
			resetForm() {
				this.form = JSON.parse(JSON.stringify(this.formReset))
			},
			// 获取数据列表
			getList() {
				this.listLoading = true
				this.$api.fetchList(this.queryList, this.apiPath).then(response => {
					this.tableList = response.list
					this.listTotal = response.list_count
					this.isPage = response.is_page
					this.listLoading = false
				})
			},
			// 添加
			handleAdd() {
				this.resetForm()
				this.uploadShow = true;
				this.dialogStatus = 'create'
				this.dialogFormVisible = true
				this.$nextTick(() => {
					this.$refs['dataForm'].clearValidate()
				})
			},
			// 编辑
			handleEdit(id = 0) {
				this.resetForm()
				this.uploadShow = true;
				// 获取详情
				this.$api.getDetail({
					id: id
				}, this.apiPath).then(response => {
					//数据处理
					/* if (response.detail.start_time > 0) {
					   response.detail.start_time_str = parseTime(response.detail.start_time, '{y}-{m}-{d} {h}:{i}:{s}')
					 } else {
					   response.detail.start_time_str = ''
					 }
					 if (response.detail.end_time > 0) {
					   response.detail.end_time_str = parseTime(response.detail.end_time, '{y}-{m}-{d} {h}:{i}:{s}')
					 } else {
					   response.detail.end_time_str = ''
					 }*/
					for (let key in this.form) {
						if (response.detail.hasOwnProperty(key)) {
							this.form[key] = response.detail[key]
						}
					}

					//获取行业分类列表
					// this.getIndustryList( response.detail.c_id)
				})
				this.dialogStatus = 'update'
				this.dialogFormVisible = true
				this.$nextTick(() => {
					this.$refs['dataForm'].clearValidate();
				})
			},
			// 添加-数据提交
			createData() {
				this.$refs['dataForm'].validate((valid) => {
					if (valid) {
						//标签
						this.form.tag = this.form.tag_arr.join(",");
						this.form.details3_str = JSON.stringify(this.form.details3_array)
						this.form.details4_str = JSON.stringify(this.form.details4_array)
						this.$api.add(this.form, this.apiPath).then(() => {
							// 重新获取列表
							this.queryList.curpage = 1
							this.tableList = []
							this.getList()
							this.dialogFormVisible = false
							this.uploadShow = false;
							this.$message({
								message: '添加成功',
								type: 'success'
							})
						})
					}
				})
			},
			// 编辑-数据提交
			updateData() {
				this.$refs['dataForm'].validate((valid) => {
					if (valid) {
						//标签
						this.form.tag = this.form.tag_arr.join(",");
						this.form.details3_str = JSON.stringify(this.form.details3_array)
						this.form.details4_str = JSON.stringify(this.form.details4_array)
						this.$api.edit(this.form, this.apiPath).then(response => {
							// 重新获取列表
							this.getList()

							this.dialogFormVisible = false
							this.uploadShow = false;
							this.$message({
								message: '编辑成功',
								type: 'success'
							})
						})
					}
				})
			},
			// 删除
			handleDelete(id = 0) {
				let current = this
				let id_str = ''
				if (!id) {
					// 多选
					if (!this.multipleSelection.length) {
						this.$message({
							message: '请选择删除的条目！',
							type: 'warning'
						})
						return false
					}
					// 数据处理
					this.multipleSelection.forEach(item => {
						id_str += item[current.keyName] + ','
					})
				} else {
					id_str = id
				}

				// 提交数据
				this.$confirm('确认删除数据吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$api.del({
						id_str: id_str
					}, this.apiPath).then(response => {
						// 重新获取列表
						this.getList()
						this.$message({
							message: '删除成功',
							type: 'success'
						})
					})
				})
			},
			// 排序
			updateSort(id = 0, sort = '') {
				this.$api.editSort({
					id: id,
					sort: sort
				}, this.apiPath).then(response => {
					this.$message({
						message: '排序成功',
						type: 'success'
					})
				})
			},
			//启用
			handleShow(id = 0) {
				this.$confirm('确认启用数据吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$api.show({
						id_str: id
					}, this.apiPath).then(response => {
						// 重新获取列表
						this.getList()
						this.$message({
							message: '启用成功',
							type: 'success'
						})
					})
				})
			},
			//禁用
			handleUpshow(id = 0) {
				this.$confirm('确认禁用数据吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					this.$api.upshow({
						id_str: id
					}, this.apiPath).then(response => {
						// 重新获取列表
						this.getList()
						this.$message({
							message: '禁用成功',
							type: 'success'
						})
					})
				})
			},
			/*******************************公共方法END******************************/
			/*办事条件*/
			//增
			addRowHeader(index = 0) {
				if (index) {
					this.form.details3_array.splice(index, 0, {
						name: '',
						remarks: '',
					});
				} else {
					this.form.details3_array.push({
						name: '',
						remarks: '',
					});
				}
			},
			//减
			delRowHeader(index = -1) {
				if (index >= 0) {
					this.form.details3_array.splice(index, 1);
				}
			},

			/*办事材料*/
			//增
			addRowParam(index = 0) {
				if (index) {
					this.form.details4_array.splice(index, 0, {
						name: '',
						option1: '原件',
						option2: '纸质版',
						option3: '必要',
						is_option1: false,
						is_option2: false,
						is_option3: false,
						is_title: false,
					});
				} else {
					this.form.details4_array.push({
						name: '',
						option1: '原件',
						option2: '纸质版',
						option3: '必要',
						is_option1: false,
						is_option2: false,
						is_option3: false,
						is_title: false,
					});
				}
			},
			//减
			delRowParam(index = -1) {
				if (index >= 0) {
					this.form.details4_array.splice(index, 1);
				}
			},

		}
	}
</script>